package cn.kshost.zqyg.cart.controller;

import cn.kshost.zqyg.cart.service.CartService;
import cn.kshost.zqyg.model.entity.h5.CartInfo;
import cn.kshost.zqyg.model.vo.common.Result;
import cn.kshost.zqyg.model.vo.common.ResultCodeEnum;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/order/cart/auth")
public class CartController {

    @Autowired
    private CartService cartService;
    @Operation(summary = "添加购物车")
    @GetMapping("/addToCart/{skuId}/{skuNum}")
    public Result addToCart(@PathVariable( value = "skuId") String skuId,@PathVariable(value = "skuNum") String skuNum) {
        cartService.addToCart(skuId,skuNum);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "查询购物车列表")
    @GetMapping("/cartList")
    public Result getCartList(){
       List<CartInfo> cartInfoList =  cartService.getCartList();
       return Result.build(cartInfoList,ResultCodeEnum.SUCCESS);
    }
    @Operation(summary = "删除购物车商品")
    @DeleteMapping("/deleteCart/{skuId}")
    public Result deleteCart(@PathVariable( value = "skuId") Long skuId) {
        cartService.deleteCart(skuId);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "清空购物车")
    @GetMapping("/clearCart")
    public Result clearCart() {
        cartService.clearCart();
        return  Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "更新购物车商品选中状态")
    @GetMapping("/checkCart/{skuId}/{isChecked}")
    public Result updateCheckCart(@PathVariable("skuId") Long skuId,@PathVariable("isChecked") Integer isChecked){

        cartService.updateCheckCart(skuId,isChecked);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }
    @Operation(summary = "更新购物车全部商品选中状态")
    @GetMapping("/allCheckCart/{isChecked}")
    public Result getAllCheckCart(@PathVariable("isChecked") Integer isChecked){
        cartService.getAllCheckCart(isChecked);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "获取所有选中的购物车")
    @GetMapping("/getAllCkecked")
    public Result<List<CartInfo>> getAllChecked(){
       List<CartInfo>  cartInfoList =  cartService.getAllChecked();
       return Result.build(cartInfoList,ResultCodeEnum.SUCCESS);
    }
}
